﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;

namespace VTV.TaskManagementSystem.WebApp
{
    public partial class Default1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnFilterData_Click(object sender, DirectEventArgs e)
        {
            var baseLink = Request.FilePath;
            var teamName = e.ExtraParams["TeamName"];
            var startDate = string.Empty;
            var endDate = string.Empty;
            try
            {
                startDate = e.ExtraParams["StartDate"] != null ? Convert.ToDateTime(e.ExtraParams["StartDate"]).ToShortDateString() : null;
                endDate = e.ExtraParams["EndDate"] != null ? Convert.ToDateTime(e.ExtraParams["EndDate"]).ToShortDateString() : null;
            }
            catch
            {}
            
            string link;

            if (!String.IsNullOrEmpty(teamName))
            {
                if (!String.IsNullOrEmpty(startDate) && !String.IsNullOrEmpty(endDate))
                {
                    link = String.Format(baseLink + "?team={0}&startdate={1}&enddate={2}", teamName.Trim(),
                                         startDate.Trim(), endDate.Trim());
                }
                else
                {
                    link = String.Format(baseLink + "?team={0}", teamName.Trim());
                }

                Response.Redirect(link);
            }
            else
            {
                if (!String.IsNullOrEmpty(startDate) && !String.IsNullOrEmpty(endDate))
                {
                    link = String.Format(baseLink + "?startdate={0}&enddate={1}", startDate.Trim(), endDate.Trim());

                    Response.Redirect(link);
                }
            }
        }
    }
}